package com.etc.controller;

import com.etc.entity.Users;
import com.etc.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * zj 用户控制器
 */
@CrossOrigin
@Controller
@Api(tags = "用户管理相关接口")
@RequestMapping("User")
public class UserController {
    @Autowired
    UserService service;
    @GetMapping("/login")
    @ApiOperation("用户登陆")
    @ResponseBody
    public Map<String,Object> getlogin(@RequestParam String username, @RequestParam String userpwd){
        Map<String, Object> map = new HashMap<>();
        Users users = service.getlogin(username, userpwd);
        if (users!=null) {
            map.put("user", users);
            map.put("msg","登陆成功");
        }else {
            map.put("msg","用户名或密码错误");
            map.put("user",null);
        }
        return map;
    }

    //修改个人信息
    @RequestMapping("/getModUsers")
    @ResponseBody
    public  boolean  getModUsers(@RequestParam(value = "u_id")String u_id,
                                 @RequestParam(value = "u_name")String u_name,
                                 @RequestParam(value = "u_password")String u_password,
                                 @RequestParam(value = "u_sex")String u_sex){
        //调用业务层
        boolean  fian = service.getModUsers(u_id,u_name,u_password,u_sex);
        return  fian;
    }
}
